package com.bj.zspace.flink.study.wc.mysource;

import org.apache.flink.streaming.api.functions.source.RichParallelSourceFunction;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author qing
 */
public class VideoOrderSource extends RichParallelSourceFunction<String> {

    private volatile Boolean flag = true;

    private Random random = new Random();

    private static List<String> list = new ArrayList<>();
    static {
        list.add("hello java");
        list.add("hello python");
        list.add("hello go");
        list.add("hello dark");
        list.add("hello flutter");
    }
    @Override
    public void run(SourceContext<String> ctx) throws Exception {
        while (flag){
            Thread.sleep(1000);
            int videoNum = random.nextInt(list.size());
            String title = list.get(videoNum);
            ctx.collect(title);
        }
    }

    @Override
    public void cancel() {
        flag = false;
        System.out.println("关闭");

    }
}
